home *** CD-ROM | disk | FTP | other *** search
Java Source | 1995-12-31 | 2.2 KB | 68 lines |
-
- import java.awt.*;
-
- public class DoubleBuff extends SingleBuff implements Runnable {
-
- /* double buffering stuff */
- Graphics dbuffer; // Graphics object for offscreen drawing
- Image offscreen; // Image representing the final screen
- // picture
-
- public void init() {
- AppBorder = bounds(); // get current applet boundary
- XRES = AppBorder.width;
- YRES = AppBorder.height;
- x=XRES/2-w/2; //center the image
-
- /* Create an image that is the same size */
- /* as the resolution */
- offscreen = createImage(XRES,YRES);
-
- dbuffer = offscreen.getGraphics(); //associate a Graphics obj
- dbuffer.setColor(Color.lightGray); //background color
- dbuffer.fillRect(0,0,XRES,YRES); //fill in background
- }
-
-
- /* The paint method */
- public void paint(Graphics g) {
-
- dbuffer.setColor(Color.lightGray); // background color
- dbuffer.fillRect(x,oldy,w+1,h+1); // cover up last box drawn
- oldy=y; // remember y for the next coverup
-
- /* draw background pattern */
- for(int gc=0;gc<XRES;gc+=gw) {
- dbuffer.setColor(Color.gray); // color of gridlines
- dbuffer.drawLine(gc,0,gc,YRES); // draw vertical lines
- dbuffer.drawLine(0,gc,XRES,gc); // draw horizontal lines
- dbuffer.setColor(Color.yellow); // set color to yellow
- dbuffer.drawLine(gc,0,0,gc); // draw diags
- dbuffer.setColor(Color.blue); // set color to blue
- dbuffer.drawLine(XRES-gc,0,XRES,gc); // draw diags
- }
-
- dbuffer.setColor(Color.lightGray); // background color
- dbuffer.fillRect(0,0,100,20); // clear box for title
- dbuffer.setColor(Color.red); // set color to red
- dbuffer.drawString(XRES + " " + YRES,0,10);
- dbuffer.fillRect(x,y,w,h); // draw red square
- dbuffer.setColor(Color.blue);
-
- int l=0;
- for (int lh=h;lh>0;l+=4,lh-=8)
- dbuffer.drawOval(x+l,y+l,lh,lh);
-
- /* Notice that the only call to the g object */
- /* is on the following line. All other graphics */
- /* operations happen to the buffer */
-
- /* Transfer (blit) the offscreen to the screen */
- g.drawImage(offscreen,0,0,this);
- }
-
-
- }
-
-
-